package montecarlo.algorithms;

import java.text.DecimalFormat;

public abstract class AbstractClassMC {
	private String executionTime;
	private String result;
	private int poolSize;

	
	public void timeAndComputeValue(String[] parameters) throws NumberFormatException, Exception{
		final long start = System.nanoTime();
		final double nav = monteCarloStandardOption(parameters[0], Double
				.valueOf(parameters[1]), Double.valueOf(parameters[2]), Double
				.valueOf(parameters[3]), Double.valueOf(parameters[4]), Double
				.valueOf(parameters[5]), Double.valueOf(parameters[6]), Integer
				.valueOf(parameters[7]), Integer.valueOf(parameters[8]));
		final long end = System.nanoTime();
		final String value = new DecimalFormat("$##,###0.000").format(nav);
		System.out.println("Result= " + value);
		this.result=value;
		final String time = new DecimalFormat("##,###0.000").format((end - start) / 1.0e9);
		this.executionTime= ""+time+" sec(s)";
		System.out.println("Time= " + executionTime);
}
	/**
	 * Monte Carlo method
	 * 
	 * @param callPutFlag
	 *            Specifies whether the option is a call or put option;
	 * @param s
	 *            : The current price of the option's underlying asset;
	 * @param x
	 *            : The strike price of the option;
	 * @param t
	 *            : Time to maturity of the option (in years) ;
	 * @param r
	 *            : The discount rate (risk-free interest rate);
	 * @param b
	 *            : The cost of carry rate (cost of interest, dividends and any
	 *            other additional costs);
	 * @param v
	 *            : The volatility of the underlying asset (the standard
	 *            deviation of its market price);
	 * @param nSteps
	 *            : The number of steps to execute for each option price path
	 *            (the number of intermediate points that will be calculated on
	 *            each price path. The greater this value, the more accurate the
	 *            estimation of the path's premium);
	 * @param nSimulations
	 *            : The number of simulations to run (number of price paths to
	 *            explore).
	 * @return The premium of a European option
	 */
	public abstract double monteCarloStandardOption(final String callPutFlag,final double s,
			final double x,final  double r, final double t, final double b, final double v, final int nSteps,
			final int nSimulations) throws Exception;
	
	public String getExecutionTime() {
		return executionTime;
	}
	public void setExecutionTime(String executionTime) {
		this.executionTime = executionTime;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public int getPoolSize() {
		return poolSize;
	}

	public void setPoolSize(int poolSize) {
		this.poolSize = poolSize;
	}	
	

}
